#!/bin/bash
CURRENT_PATH=$(pwd);
ROOT_PATH=$(cd `dirname $0`/; pwd);

${ROOT_PATH}/main -t
e=$?
if [[ ${e} != 0 ]]
then
    exit ${e}
fi

rm -rf /usr/sbin/neutron
ln -s ${ROOT_PATH}/main /usr/sbin/neutron
rm -rf /usr/local/neutron
ln -s ${ROOT_PATH} /usr/local/neutron

source /etc/os-release
case $ID in
debian|ubuntu)
    cat ${ROOT_PATH}/neutron.conf > /etc/init/neutron.conf

    cat ${ROOT_PATH}/ubuntu.service > /lib/systemd/system/neutron.service

    cat ${ROOT_PATH}/init.d > /etc/init.d/neutron
    sleep 1
    chmod 755 /etc/init.d/neutron
    ;;
centos|fedora|rhel)
    cat ${ROOT_PATH}/centos.service > /usr/lib/systemd/system/neutron.service
    ;;
*)
    exit 1
    ;;
esac

if [[ ! -e "/etc/neutron/" ]]
then
    mkdir -p /etc/neutron/
fi
cat ${ROOT_PATH}/config.yaml > /etc/neutron/config.yaml

systemctl enable neutron

service neutron restart
